home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / newsgroups / misc.19960209-19960425 / 000252_news@columbia.edu _Thu Mar 21 09:19:19 1996.msg < prev    next >
Internet Message Format  |  2020-01-01  |  3KB

  1. Return-Path: news@columbia.edu
  2. Received: from apakabar.cc.columbia.edu (apakabar.cc.columbia.edu [128.59.35.159]) by watsun.cc.columbia.edu (8.7.3/8.7.3) with ESMTP id JAA26374 for <kermit.misc@watsun>; Thu, 21 Mar 1996 09:19:19 -0500 (EST)
  3. Received: (from news@localhost) by apakabar.cc.columbia.edu (8.7.3/8.7.3) id JAA06656 for kermit.misc@watsun; Thu, 21 Mar 1996 09:19:16 -0500 (EST)
  4. Path: news.columbia.edu!watsun.cc.columbia.edu!fdc
  5. From: fdc@watsun.cc.columbia.edu (Frank da Cruz)
  6. Newsgroups: comp.protocols.kermit.misc
  7. Subject: Re: Cycle thru arguments?
  8. Date: 21 Mar 1996 14:18:56 GMT
  9. Organization: Columbia University
  10. Lines: 90
  11. Message-ID: <4irogg$6fn@apakabar.cc.columbia.edu>
  12. References: <31509f0c.83643245@news.vnet.net>
  13. NNTP-Posting-Host: watsun.cc.columbia.edu
  14.  
  15. In article <31509f0c.83643245@news.vnet.net>,
  16. Milton Baucom <mbaucom@vnet.net> wrote:
  17. : Given that \v(argc) will give me the number of arguements to a macro,
  18. : and I can access them via \%1, \%2, etc., how can I programatically
  19. : select which arguement to look at.
  20. : For instance, I want a for loop using \v(argc) to echo each arg.  I
  21. : can't seem to make that happen.
  22. You didn't say whether you were using C-Kermit or MS-DOS Kermit.  In
  23. C-Kermit, the technique is easy (if not totally obvious):
  24.  
  25.   def xx -
  26.     echo ARGC = \v(argc), -
  27.     asg \%i 0, -
  28.   :loop,-
  29.     asg \%x \\%\%i, -
  30.     echo \\%\%i = \%x, -
  31.     increment \%i, -
  32.     if < \%i \v(argc) goto loop
  33.  
  34. Here we compose the name of the argument variable and assign it to \%x:
  35.  
  36.   asg \%x \\%\%i
  37.  
  38. then we evaluate \%x:
  39.  
  40.   echo ... \%x
  41.  
  42. Since evaluation of a variable is recursive (unless we say otherwise), \%x
  43. evaluates to \%3 or whatever, which is then itself evaluated, revealing
  44. the macro argument value:
  45.  
  46.   xx a b c
  47.   ARGC = 4
  48.   \%0 = xx
  49.   \%1 = a
  50.   \%2 = b
  51.   \%3 = c
  52.  
  53. Your seemingly innocent question, unfortunately, revealed all sorts of
  54. little problems.  First of all, the C-Kermit example above should have
  55. been codable as a FOR-loop:
  56.  
  57.   def xx -
  58.     echo ARGC = \v(argc), -
  59.     for \%i 0 \v(argc) 1 { -
  60.       asg \%x \\%\%i, -
  61.       echo \\%\%i = \%x, -
  62.     }
  63.  
  64. But that doesn't work because the wrong value is used for \v(argc).
  65. It does work, however, if you make a copy first:
  66.  
  67.   def xx -
  68.     asg \%n \v(argc), -
  69.     echo ARGC = \%n, -
  70.     for \%i 0 \%n 1 { -
  71.       asg \%x \\%\%i, -
  72.       echo \\%\%i = \%x, -
  73.     }
  74.  
  75. For MS-DOS Kermit, we go back to the first example, since MS-DOS Kermit
  76. doesn't (yet) have FOR loops.  Unfortunately, it doesn't work, and no
  77. amount of trickery seems to let us "compose" a variable name on the fly.
  78. So the following stupid technique can be used instead (of course it also
  79. works in C-Kermit):
  80.  
  81.   def yy -
  82.     echo ARGC = \v(argc), -
  83.     asg \%i 0, -
  84.   :loop,-
  85.     if = \%i 0 asg \%x \%0, -
  86.     if = \%i 1 asg \%x \%1, -
  87.     if = \%i 2 asg \%x \%2, -
  88.     if = \%i 3 asg \%x \%3, -
  89.     if = \%i 4 asg \%x \%4, -
  90.     if = \%i 5 asg \%x \%5, -
  91.     if = \%i 6 asg \%x \%6, -
  92.     if = \%i 7 asg \%x \%7, -
  93.     if = \%i 8 asg \%x \%8, -
  94.     if = \%i 9 asg \%x \%9, -
  95.     echo \%i. \%x, -
  96.     increment \%i, -
  97.     if < \%i \v(argc) goto loop
  98.  
  99. What we probably should do (besides fixing the bugs noted above) is make
  100. the argument vector available in an array that is local to the macro.
  101.  
  102. - Frank